/* Show Markov chain graphically */

#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
#include <QStyleOptionGraphicsItem>
#include <QPrinter>
#include <QList>

#include "itf_showMarkov.h"
#include "itf_garrangement.h"
#include "itf_mc.h"

#include "mex.h"

using namespace std;

extern void _main();

extern void itf_mc(markovChain *mc, int nrhs, const mxArray *prhs[]);

void mexFunction(int nlhs, mxArray *[], int nrhs, const mxArray *prhs[]) {
    
    int argc = 0;
    char **argv = NULL;
    markovChain mc;
    
    QApplication app( argc, argv );
    
    /* Create graphic visualizer */
    GraphicArrangement *graphicVisualizer = new GraphicArrangement();
    
    
    itf_mc(&mc, nrhs, prhs);
    
    /* Create the states in gv */
    graphicVisualizer->fromMc(mc);
    /* End the creation of states */
    
	graphicVisualizer->setLayout("dot");
    
    QGraphicsScene scene(graphicVisualizer->boundingRect());
    
    graphicVisualizer->display(&scene);
    
    /* Remove GraphicArrangement */
	delete graphicVisualizer;
    
	QGraphicsView view;
	view.setScene(&scene);
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
	/*view.setViewport(new QGLWidget());*/
	view.show();
	
	app.exec();
}
